#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

int n, a[3];
int ans;

int trans(int x, int y, int z) {
	if(y == z) return y;
	if(y > z) swap(y, z);
	if((z - y) % 3) return 1e9 + 7;
	int ned = (z - y) / 3;
	if(x + y <= 0) return 1e9 + 7;
	z -= ned; y += ned * 2; x -= ned;
	return y + ned;
}

void solve() {
	n = 0;
	rep(i, 0, 2) a[i] = in, n += a[i];
	ans = 1e9;
	rep(i, 0, 2) ans = min(ans, trans(a[i], a[(i + 1) % 3], a[(i + 2) % 3]));
	if(ans == 1e9) ans = -1;
	printf("%d\n", ans);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    int T = in; while(T--) solve();
}
